<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #app {
            display: flex;
            margin: 100px auto;
            width: 300px;
            height: 100px;
            text-align: center;
        }
        
        button {
            flex: 1;
        }
        
        span {
            flex: 1;
        }
    </style>
</head>

<body>
    <div id="app">
        <button @click="sub">-</button>
        <span>
            {{message}}
        </span>
        <button v-on:click="add">+</button>
    </div>
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                message: '0',
            },
            methods: {
                add: function() {
                    if (this.message < 10) {
                        this.message++
                    } else {
                        alert('最大了')
                    }
                },
                sub: function() {
                    if (this.message > 0) {
                        this.message--
                    } else {
                        alert('最小了')
                    }
                }
            }
        })
    </script>
</body>

</html>